package com.handtransaction.service.impl;

import com.handtransaction.dao.GoodsDao;
import com.handtransaction.dao.OffShelfGoodsDao;
import com.handtransaction.entity.Administrator;
import com.handtransaction.entity.Goods;
import com.handtransaction.entity.OSGoods;
import com.handtransaction.service.OffShelfService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OffShelfImpl implements OffShelfService {
    @Autowired
    private OffShelfGoodsDao osgdao;
    @Autowired
    private GoodsDao goodsDao;

    @Override
    public int createOffShelfGoods(Administrator admin , Integer gid , String reason) {
        OSGoods osGoods = new OSGoods();
        Goods goods = goodsDao.queryGoodBygid(gid);
        //将数据封装到OSGoods中
        osGoods.setOsadminid(admin.getAid());
        osGoods.setOsadminname(admin.getAname());
        osGoods.setOsgid(goods.getGid());
        osGoods.setOsgname(goods.getGname());
        osGoods.setOsgsrc(goods.getGimg_path());
        osGoods.setOsguid(goods.getGuid());
        osGoods.setOsreason(reason);
        return osgdao.insertOSGoods(osGoods);
    }

    @Override
    public List<OSGoods> queryAllOSGoods() {
        return osgdao.queryAllOSGoods();
    }
}
